/************************************************************
wx
2020/2/2

*************************************************************/

using System.Collections;
using System.Collections.Generic;
using Fight;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class CardItem : MonoBehaviour, IPointerClickHandler
{
    public Card Card { get; private set; }

    private Text m_txtName;
    private Image m_imgBg;

    private void Awake()
    {
        m_txtName = transform.Find("txtName").GetComponent<Text>();
        m_imgBg = transform.GetComponent<Image>();
    }

    public void SetCard(Card card)
    {
        Card = card;
    }

    public void UpdateItem()
    {
        if (Card != null)
        {
            if (m_txtName != null)
            {
                m_txtName.text = Card.Name;
            }
        }
    }

    public void Destroy()
    {
        Destroy(gameObject);
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        MessageManager.Instance.Excute(MessageType.SelectCard, Card);
    }

    public void OnClick(bool bSelect)
    {
        if (bSelect)
        {
            m_imgBg.color = Color.red;
        }
        else
        {
            m_imgBg.color = Color.white;
        }
    }
}
